var http = require('http');
var fs = require('fs');
var path = require('path');

http.createServer((req,res)=>{
    if (!process.argv[2]) {
        var tempPath = __filename;

        fs.readFile(tempPath,(err,data)=>{
            if (err) {
                console.log(err);
                
            }
            else{
                res.writeHead(200,{"content-Type":"text/html;charset=utf-8"});
                res.end(data);
            }
        })
    }
    else{
        var fname = process.argv[2];
        var tempPath = path.join(__dirname,fname);

        fs.readFile(tempPath,(err,data)=>{
            if (err) {
                console.log(err);
                
            }
            else{
                res.writeHead(200,{"content-Type":"text/html;charset=utf-8"});
                res.end(data);
            }
        })
    }
}).listen(8081);
console.log('Server is listening 8081');